import * as api from '@/api/homepage';

export default {
  namespaced: true,
  state: {
    // 新闻列表
    newsList: [],
    // 用户频道列表
    channelList: [],
    // 全部频道列表
    allChannelList: [],
  },
  mutations: {
    setNewsList (state, newValue) {
      state.newsList = newValue;
    },
    setChannelList (state, newValue) {
      state.channelList = newValue;
    },
    setAllChannelList (state, newValue) {
      state.allChannelList = newValue;
    },
  },
  actions: {
    async updateNewsList (ctx, id) {
      const res = await api.getNewsList(id);
      ctx.commit('setNewsList', res);
    },
    async updateChannelList (ctx) {
      const res = await api.getChannelList();
      ctx.commit('setChannelList', res);
    },
    async updateAllChannelList (ctx) {
      const res = await api.getAllChannelList();
      ctx.commit('setAllChannelList', res);
    },
  },
}
